<?php

use Doraemon\service\User;
use Biz\cache\activity\McnUser as cacheMcnUser;
use Doraemon\service\Follow;
use Doraemon\service\statSign\Basic as basicStatSign;
use Doraemon\pockets\constInterface\statSign\AutoModule;
use Doraemon\tools\BlockType;
use hhz\constant\redis\redisKeys;


class StarUserAction extends ActionPlugin
{
    public const USER_LEVEL = self::LEVEL_REALNAME;

    /**
     * @throws Exception
     */
    public function main()
    {
//        $starUsers =  cacheMcnUser::getItems();
        $sConstKey = redisKeys::KEY_C_OTHER_MCN_USER;
        $redis = new \Hhz\Redis\otherRedis($sConstKey);
        $starUsers = $redis->smembers($sConstKey);
        $recommUIds = [];
        if($starUsers && is_array($starUsers)){
            $UserMapTag = [];
            $uids = [];
            foreach ($starUsers as $val){
                 $mapInfo =    explode("-" , $val);
                 $UserMapTag[$mapInfo[0]] = $mapInfo[1];
                 $uids[] = $mapInfo[0];
            }
            $followStatus = Follow::isFollowedMulti($this->uid,$uids );
            $no_follow_uids = [];
            $follow_uids = [];
            foreach($followStatus as $uid=>$status){
                if($status == 1) {
                    $follow_uids[] = $uid;
                }else{
                    $no_follow_uids[] = $uid;
                }
            }
            if(count($no_follow_uids) >= 8){
                shuffle($no_follow_uids);
                $recommUIds =  array_slice($no_follow_uids , 0 ,8);
            }else{
                shuffle($follow_uids);
                $follow_uids = array_slice($follow_uids , 0 , 8- count($no_follow_uids));
                $recommUIds= array_merge($no_follow_uids ,$follow_uids );
            }
        }
        $info =  User::getBatchBasicUserInfo($recommUIds , $this->uid);
        if($info && is_array($info)){
            foreach($info as &$val){
                $val['personal_preference'] = $UserMapTag[$val['uid']] ? : '';
                $val['statSign'] =  basicStatSign::genStatSign(AutoModule::MODULE_COMMON_ACTIVITY_USER_CARD, [
                    basicStatSign::EXTEND_KEY_OBJ_TYPE => 1105,
                    basicStatSign::EXTEND_KEY_OBJ_ID => $val['uid'],
                ], [ "uid" => $this->uid,  "obj_id" => $val['uid'], "obj_type" => 1105, 'activity_name' => "buyers_land"]);;
            }
        }

        $this->setSuccess( $info);
    }





}